package com.jiepu.homework.module5.exercise6;

import java.util.Scanner;

public class Test {

	public static void main(String[] args) {

		Teacher t1 = new Teacher(2001, "张三", 40, "男", 20000.00);
		Teacher t2 = new Teacher(2002, "李四", 35, "女", 15000.00);
		Teacher t3 = new Teacher(2003, "王五", 30, "男", 10000.00);

		Student[] stus = new Student[4];
		stus[0] = new Student(1001, "Tom", 22, "男", "tom1314", "tompwd123", t1);
		stus[1] = new Student(1002, "Jack", 22, "男", "j885983", "jackiou", t2);
		stus[2] = new Student(1003, "Lucy", 23, "女", "lucy321", "112233", t1);
		stus[3] = new Student(1004, "Lily", 21, "女", "ll8888", "ll8888", t3);

		Scanner sc = new Scanner(System.in);

		String username = null;
		String password = null;
		loop1: while (true) {
			System.out.println("请输入您的账号：");
			username = sc.nextLine();
			for (int i = 0; i < stus.length; i++) {
				Student s = stus[i];
				if (username.equals(s.getUsername())) {
					break loop1;
				}
			}
			System.out.println("账号不存在，请重新输入！");
		}

		while(true) {
			System.out.println("请输入您的密码：");
			password = sc.nextLine();
			// 找到刚才试图登录的那个学生信息
			for (int i = 0; i < stus.length; i++) {
				Student s = stus[i];
				if (s.getUsername().equals(username)) {
					if (password.equals(s.getPassword())) {
						System.out.println("登录成功！");
						System.out.println(s);
						System.exit(0);
					} else {
						System.out.println("密码错误，请重新输入！");
						break;
					}
				}
			}
		}
	}
}
